<template>
  <div>
    <div class="header_search_nav search_form">
      <div class="ipt_left">
        <el-form ref="queryForm" :model="queryParams" label-width="80px">
          <el-row>
            <el-col :span="6">
              <el-form-item label="项目名称" prop="itemName">
                <el-input
                  class="w-200"
                  v-model="queryParams.itemName"
                  placeholder="请输入项目名称"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="项目分类" prop="typeId">
                <el-select
                  v-model="queryParams.typeId"
                  placeholder="请选择"
                  class="w-200"
                >
                  <el-option
                    v-for="item in SortList"
                    :key="item.typeId"
                    :label="item.typeName"
                    :value="item.typeId"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="项目状态" prop="sellStatus">
                <el-select
                  v-model="queryParams.sellStatus"
                  placeholder="请选择"
                  class="w-200"
                >
                  <el-option
                    v-for="item in ProjrctOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="门店分类" prop="itemStoreTypeId">
                <el-select
                  v-model="queryParams.itemStoreTypeId"
                  placeholder="请选择"
                  class="w-200"
                >
                  <el-option
                    v-for="item in itemStoreOptions"
                    :key="item.itemStoreTypeId"
                    :label="item.typeName"
                    :value="item.itemStoreTypeId"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <div class="btn_right">
        <button class="btn1" @click="handleQuery">筛选</button>
        <button class="btn2" @click="resetQuery">重置</button>
      </div>
    </div>

    <!-- 项目列表 -->
    <div class="table_card">
      <!-- 上部分 title -->
      <div class="table_card_top">
        <span class="solid_left"></span>
        <div class="table_card_title">项目列表</div>
        <div class="op_right">
          <button class="primary_button" @click="handleAdd">发布项目</button>
        </div>
      </div>

      <div class="table_list">
        <el-table :data="ProjectData" stripe style="width: 100%">
          <el-table-column prop="reorder" label="项目排序"></el-table-column>
          <el-table-column prop="itemName" label="项目名称"></el-table-column>
          <el-table-column prop="typeName" label="项目分类"></el-table-column>
          <el-table-column
            prop="itemStoreTypeName"
            label="门店分类"
          ></el-table-column>
          <el-table-column prop="itemDuration" label="项目时长（分钟）">
          </el-table-column>
          <el-table-column prop="itemPrice" label="项目金额（元）">
          </el-table-column>
          <el-table-column prop="usedCount" label="应用门店">
            <template slot-scope="scope">
              <div>{{ scope.row.usedCount }}</div>
              <div class="hover_style2" @click="handleCheck(scope.row)">
                点击查看
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="sellStatus" label="项目状态">
            <template slot-scope="scope">
              {{ saleStatusObj[scope.row.sellStatus] }}
            </template>
          </el-table-column>
          <el-table-column prop="appletStatus" label="小程序显示状态">
            <template slot-scope="scope">
              {{ appletStatusObj[scope.row.appletStatus] }}
            </template>
          </el-table-column>
          <el-table-column prop="date" label="操作">
            <template slot-scope="scope">
              <el-button size="mini" type="text" @click="edit(scope.row)"
                >编辑</el-button
              >

              <el-button
                size="mini"
                type="text"
                :disabled="
                  scope.row.sellStatus === 0 || scope.row.sellStatus === '0'
                    ? true
                    : false
                "
                @click="Takedown(scope.row, 0)"
                >上架</el-button
              >

              <el-button
                size="mini"
                type="text"
                :disabled="
                  scope.row.sellStatus === 1 || scope.row.sellStatus === '1'
                    ? true
                    : false
                "
                @click="Takedown(scope.row, 1)"
                >下架</el-button
              >
              <el-button size="mini" type="text" @click="dele(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>

      <!-- 列表 点击查看 -->
      <el-dialog
        title="应用门店"
        :visible.sync="CheckStoresdialogVisible"
        width="500px"
      >
        <span>
          <div class="list_Stores">
            <div
              class="list_Stores_item"
              v-for="(item, index) in storesList"
              :key="index"
            >
              {{ item.name }}
            </div>
          </div>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import {
  getProjectPage,
  DeleteProject,
  updateItemSimple,
  getProjectSortPage,
  getStoresInfoList,
  getStoreListByItemId,
  getProjectStoreSortPage,
} from "@/api/business/project";
export default {
  name: "EryuoaStoreFrontendtabList",

  data() {
    return {
      loading: false,
      activeIndex: 1,
      currentIndex: 1,
      ProjectData: [], // 项目列表数据
      StoreSlist: [], // 门店列表数据
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        itemName: "",
        typeId: "",
        sellStatus: null,
        itemStoreTypeId: "",
      },
      // 查询参数
      queryParams2: {
        // pageNo: 1,
        // pageSize: 10,
      },

      // 查询参数
      queryParam: {
        pageNo: 1,
        pageSize: 10,
      },

      itemStoreOptions: [], // 门店分类
      total: 0,
      textarea: "",
      value1: "",

      SortList: [],

      // 销售状态
      saleStatusObj: {
        0: "上架",
        1: "下架",
      },

      appletStatusObj: {
        Y: "显示",
        N: "不显示",
      },

      ProjrctOptions: [
        {
          value: "0",
          label: "上架",
        },
        {
          value: "1",
          label: "下架",
        },
        // {
        //   value: "2",
        //   label: "全部",
        // },
      ],

      // options: [
      //   {
      //     value: "选项1",
      //     label: "黄金糕",
      //   },
      // ],
      CheckStoresdialogVisible: false, // 项目列表 点击查看门店
      storesList: [], // 应用门店
      storesLoading: false,
    };
  },

  created() {
    this.getList();
    this.getLists();
    this.projectSortSelect(); // 项目分类
  },

  mounted() {},

  methods: {
    getLists() {
      getProjectStoreSortPage(this.queryParam)
        .then((res) => {
          const { code, data } = res;
          if (code === 0) {
            this.itemStoreOptions = data.list;
          }
        })
        .catch((err) => {});
    },

    // 项目分类
    projectSortSelect() {
      this.loading = true;
      getProjectSortPage(this.queryParams2)
        .then((res) => {
          // console.log(res);
          this.loading = false;
          const { code, data } = res;
          if (code === 0) {
            this.SortList = data;
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },

    // 取消 查看门店
    CancleCheckStore() {
      this.CheckStoresdialogVisible = false;
      this.storesLoading = false;
      this.storesList = [];
    },

    // 确认 查看门店
    CheckStore() {
      this.CheckStoresdialogVisible = false;
      this.storesLoading = false;
      this.storesList = [];
    },

    // 列表点击查看
    handleCheck(row) {
      this.CheckStoresdialogVisible = true;
      this.getStoresList(row);
    },

    // 门店列表
    getStoresList(row) {
      this.storesLoading = true;
      getStoreListByItemId({ itemId: row.itemId })
        .then((res) => {
          console.log(res);
          this.storesLoading = false;
          const { code, data } = res;
          if (code === 0) {
            this.storesList = data;
            // this.total = data.total;
          }
        })
        .catch((err) => {
          this.storesLoading = false;
        });
    },

    getList() {
      this.loading = true;
      getProjectPage(this.queryParams)
        .then((res) => {
          console.log(res);
          this.loading = false;
          const { code, data } = res;
          if (code === 0) {
            this.ProjectData = data.list;
            this.total = data.total;
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },

    // 筛选
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetFormData("queryForm");
      this.handleQuery();
    },

    // 表单重置
    resetFormData(formName) {
      console.log(this.$refs[formName]);
      this.$refs[formName].resetFields();
    },

    // 列表 删除
    dele(row) {
      this.$confirm("商品删除后无法撤销, 是否删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          DeleteProject({ id: row.itemId }).then((res) => {
            const { code } = res;
            if (code === 0) {
              this.getList();
              this.$message({
                type: "success",
                message: "删除成功!",
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    // 列表 下架
    Takedown(row, status) {
      this.$confirm(
        "商品下架后门店无法使用, 是否" + (status === 0 ? "上架" : "下架") + "?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          this.editStatus(row, status);
        })
        .catch(() => {});
    },

    editStatus(row, status) {
      this.loading = true;

      updateItemSimple({
        itemId: row.itemId,
        sellStatus: status,
      })
        .then((response) => {
          this.loading = false;
          const { code, data, msg } = response;
          if (code === 0) {
            this.getList();
            this.$message({
              message: "操作成功",
              type: "success",
            });
          }
        })
        .catch((e) => {
          this.loading = false;
        });
    },

    handleAdd() {
      this.$router.push({
        path: "/storeAdminproject/storeAdminprojectlist/storeAdminaddProject",
      });
    },

    edit(row) {
      this.$router.push({
        path: "/storeAdminproject/storeAdminprojectlist/storeAdmineditProject",
        query: { id: row.itemId },
      });
    },

    rest() {
      //   this.queryParams.deptId = undefined;
      //   this.queryParams.mobile = "";
    },
  },
};
</script>

<style lang="scss" scoped>
.w-200 {
  width: 200px;
  background: #ffffff;
  border-radius: 4px;
}

.client_name {
  font-size: 14px;
  font-weight: 400;
  color: #0052d9;
}

.give {
  height: 40px;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
  margin-top: 40px;
  line-height: 40px;
}

.el-form-item {
  margin-bottom: 20px;
}

.recharge_form {
  padding: 10px 24px;
}

.memberName {
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
}
.el_row_item {
  margin-bottom: 10px;
}
.el_row_date {
  margin-top: 20px;
}
.el_row_reason {
  margin-top: 10px;
}

.el_row_date {
  .el-form-item {
    margin-bottom: 0px;
  }
}

.separate_left {
  width: 1px;
  height: 14px;
  // background: #e9e9e9;
  margin-right: 12px;
}
.separate_right {
  width: 1px;
  height: 14px;
  // background: #e9e9e9;
  margin-left: 12px;
}

.check {
  font-size: 12px;
  color: #0052d9;
}

.list_Stores {
  height: 200px;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.9);
  line-height: 22px;
  .list_Stores_item {
    height: 46px;
    line-height: 46px;
    background: #ffffff;
    padding-left: 47px;
    border-bottom: 1px solid #e7e7e7;
  }
}
</style>
